var express = require('express');
var router = express.Router();
var message = require('../model/returnMessage');
var auth = require('../middleware/auth');
var { encryption } = require('../middleware/encrypt-password');
const {
  userPortraitValidator,
  getInfoValidator,
  setInfoValidator,
  setPasswordValidator,
} = require('../middleware/users');
const {
  setPortrait,
  getPortrait,
  getAccountInfo,
  setAccountInfo,
  setPassword,
  setPortraitInfo,
} = require('../controller/users');

router.post('/', auth, function (req, res, next) {
  res.json(
    message(
      { username: req.body.username },
      'JWT token verification succeeded.'
    )
  );
});

router.get('/:username/portrait', [auth, userPortraitValidator], getPortrait);

router.get('/:username/info', [auth, getInfoValidator], getAccountInfo);

//router.post('/portrait/upload', auth, setPortrait, setPortraitInfo);

router.put('/resetpwd', [auth, setPasswordValidator, encryption], setPassword);

router.put('/setinfo', [auth, setInfoValidator], setAccountInfo);

module.exports = router;
